(function() {
    var SMT = window.SMT = function() {
        if (typeof SMT == 'undefined') 
            return window;
        else 
            return SMT;
    };
    var sublistparms = (typeof sublistparms == 'undefined' || typeof sublistparms != 'obj' ? {} : sublistparms);
    SMT.version = '1.0';
    var puri = window.location.href, index = 0, B = navigator.userAgent.toLowerCase(), xcase;
    SMT.$id = function() {
        return document.getElementById(arguments[0]);
    };
    SMT.browser = {
        version: (B.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, "0"])[1],
        safari: /webkit/.test(B),
        opera: /opera/.test(B),
        msie: /msie/.test(B) && !/opera/.test(B),
        mozilla: /mozilla/.test(B) && !/(compatible|webkit)/.test(B)
    };
    SMT.isStrict = document.compatMode == "CSS1Compat";
    if ((index = puri.indexOf('.do')) > 0) {
        puri = puri.substr(0, index);
    }
    //得到controller
    puri = puri.substr(puri.lastIndexOf('/') + 1);
    //定义配置
    SMT.xconfig = {
        svar: {},
        xcaseConfig: {
            urlXcase: '',
            urlParams: ''
        }
    };
    // 编辑器
    SMT.ckeditor = null;
    //定义工具
    SMT.util = {};
    //
    SMT.listPageCount = 0;
    SMT.isNowPop = false;
    //其他菜单的拓展操作
    SMT.showSubMenu = function(id) {
        $('.options').each(function() {
            if ($(this).attr('id') != id) {
                $(this).css('display', 'none');
            }
        });
        this.isNowPop = true;
        if ($('#' + id).css('display') == 'none') {
            var lis = $('#' + id).find('li');
            var count = 0;
            lis.each(function() {
                if ($(this).css('display') == 'none') {
                    count++;
                }
            });
            if (count != lis.length) {
                $('#' + id).css('display', '');
            }
        }
        else {
            $('#' + id).css('display', 'none');
        }
        if (typeof parent.switchObj != 'undefined') {
            parent.$('.options').css('display', 'none');
        }
    };
    //语言版本的点击操作
    SMT.initLanEdition = function() {
        $('#edNamOptions li').click(function() {
            //var url='/'+config.lans.path+'?locale='+config.lans.locale+'&lanEdition='+$(this).attr('edition');
            //var url = '/' + '?locale=' + config.lans.locale + '&lanEdition=' + $(this).attr('edition');
            var url = '/' + '?lanEdition=' + $(this).attr('edition');
            url += '&module=' + config.lans.path;
            parent.window.location = url;
        });
    };
    SMT.initPage = function(invokeAction) {
        if (typeof jQuery == 'undefined') {
            return;
        };
        //浏览器拖动变小的时候，页面不变形
        $(document.body).css('min-width', '940px');
        //在建站项目中，不进行缩小
        if (typeof global == 'undefined') {
            $(document.body).css('min-width', '960px');
        }
        //动态隐藏成功提示
        jQuery('#okMessage').fadeOut(3000);
        SMT.initLanEdition();
        SMT.removeModuleIframeScrollBar();
        SMT.tag_a_click();
        var smtConfig = SMT.xconfig;
        if (typeof invokeAction != 'undefined' && invokeAction != '') {
            SMT.ajax(smtConfig[invokeAction]);
        }
        else if (smtConfig.xcaseConfig.listXcase) {
            SMT.ajax();
        }
    };
    SMT.lastAction = null;
    SMT.ajax = function(processObj) {
        processObj = processObj || (SMT.xconfig && SMT.xconfig.list);
        if (typeof processObj == 'undefined') {
            return;
        }
        if (typeof calendarGlobal != 'undefined' && calendarGlobal) 
            calendarGlobal.hide();
        //处理之前函数调用，如果返回false将终止
        if (jQuery.isFunction(processObj['callCheck'])) {
            if (!processObj['callCheck']()) 
                return;
        }
        if (processObj['processing']) {
            return;
        }
        //设置加载进度
        SMT.waiting('show');
        processObj['processing'] = true;
        //复制相关参数
        var postdata = {};
        //复制语言相关参数
        if (SMT.xconfig.lans) {
            postdata['locale'] = SMT.xconfig.lans.locale;
            postdata['lanEdition'] = SMT.xconfig.lans.lanEdition;
        }
        if (processObj['needVar']) {
            if (SMT.xconfig.gvar) 
                SMT.copyObj(postdata, SMT.xconfig.gvar);
            if (SMT.xconfig.svar) 
                SMT.copyObj(postdata, SMT.xconfig.svar);
        }
        if (processObj['argsOrder'] && processObj['args']) {
            for (var i = 0; i < processObj['argsOrder'].length; i++) {
                if (processObj['args'][i]) {
                    //数组对象可以作为参数发送
                    if (typeof processObj['args'][i] == 'object' && typeof processObj['args'][i].length == 'undefined') 
                        continue;
                    postdata[processObj['argsOrder'][i]] = processObj['args'][i];
                }
            }
        }
        if (processObj['sendRange']) {
            jQuery('input,select,textarea', processObj['sendRange']).each(function() {
                var jDom = jQuery(this);
                if (jDom.attr('type') == 'radio') { //by liyuhang
                    var v = jQuery('input[name=' + jDom.attr('name') + ']:checked').val();
                    if (v != 'undefined') {
                        postdata[this.name] = v;
                    }
                }
                else if (jDom.attr('type') != 'button' && jDom.attr('type') != 'sumit') {
                    postdata[this.name] = jDom.val();
                }
            });
        }
        //
        //var url='/'+(processObj['c']?processObj['c']:puri)+'.do?'+('navigate'==processObj['c']?'jspUrl='+processObj['jspUrl']:'xcase='+xcase);
        var url = processObj['url'];
        //
        //postdata.ajaxpage = 'yes';
        //alert(url);
        var ajaxMethod = 'get';
        if (typeof processObj['isPost'] != 'undefined' && processObj['isPost'] == true) {
            ajaxMethod = 'POST';
        }
        jQuery.ajax({
            type: ajaxMethod,
            url: url,
            data: postdata,
            cache: false,
            complete: function(xhr) {
                //window.scrollTo(0, 0);
                if (processObj['replaceExp'] && processObj['replaceExp'] == '#rightBar') {
                    if (typeof SWFUploader == 'object') {
                        SWFUploader.destroy();
                    }
                    parent.window.scrollTo(0, 0);
                    //用于隐藏自定义条目的弹出层
                    $('#itemType').css('display', 'none');
                    $('#fieldSaveDiv').css('display', 'none');
                    $('#fieldList').html('<img src="/images/icon/loading.gif" width="16" height="16" hspace="5" align="absmiddle"/>');
                    //保存之前的action
                    var curAction = $('#curAction');
                    if (curAction.length != 0) {
                        SMT.lastAction = curAction.val();
                    }
                }
                //右键菜单消失
                jQuery('.contextMenu').hide();
                //
                processObj['processing'] = false;
                SMT.waiting('hidden');
                //var successHeader=xhr.getResponseHeader("requestSuccess4Ajax");
                var successHeader = '1';
                if (successHeader == '0') {
                    if (confirm('操作超时，是否重新登录？')) {
                        var location = window.location;
                        top.location = location.protocol + '//' + location.hostname + '/logout';
                    }
                    return;
                }
                var ajaxResult = xhr.responseText;
                if (processObj['replaceExp']) {
                    jQuery(processObj['replaceExp']).html(ajaxResult);
                }
                //动态隐藏成功提示 inf
                if (jQuery('#okMessage').attr('class') != 'inf') {
                    jQuery('#okMessage').fadeOut(3000);
                }
                //按钮菜单的mouseover,mouseout
                $('#toolBar #editBtn > div').each(function() {
                    var cur$ = $(this);
                    cur$.hover(function() {
                        $(this).addClass("on");
                    }, function() {
                        $(this).removeClass("on");
                    });
                });
                //针对列表的回调
                if (processObj['isList']) {
                    //注册多选
                    SMT.allSelect();
                    //注册shift多选
                    SMT.shiftSelect();
                }
                //调用配置的回调函数
                if (jQuery.isFunction(processObj['callBack'])) {
                    if (processObj['ajaxType'] && processObj['ajaxType'] == 'json') {
                        ajaxResult = new Function('return ' + ajaxResult);
                        ajaxResult = ajaxResult();
                    }
                    processObj['callBack'].apply(processObj, [ajaxResult]);
                }
                //SMT.removeModuleIframeScrollBar();
                delete processObj['fromClick'];
                delete processObj['elm'];
            }
        });
    };
    SMT.post = function() {
        var url = '', postdata = {}, callback;
        if (typeof arguments[0] != 'undefined') {
            url = arguments[0];
        }
        if (typeof arguments[1] != 'undefined') {
            if (typeof arguments[1] == 'function') {
                callback = arguments[1];
            }
            else if (typeof arguments[1] == 'object') {
                postdata = arguments[1];
            }
        }
        if (typeof arguments[2] != 'undefined' && typeof arguments[2] == 'function') {
            callback = arguments[2];
        }
        jQuery.ajax({
            type: "POST",
            url: url,
            data: postdata,
            cache: false,
            complete: function(xhr) {
                //var successHeader = xhr.getResponseHeader("requestSuccess4Ajax");
                var successHeader = '1';
                if (successHeader != '1') {
                    if (confirm('操作超时，是否重新登录？')) {
                        var location = window.location;
                        top.location = location.protocol + '//' + location.hostname + '/logout';
                    }
                    return;
                }
                var ajaxResult = xhr.responseText;
                if (jQuery.isFunction(callback)) {
                    callback.apply(this, [ajaxResult]);
                }
            }
        });
    };
    SMT.func = function(processObj) {
        if (typeof processObj == 'undefined') {
            alert('need config');
            return;
        }
        if (!processObj['args']) 
            processObj['args'] = [];
        //处理之前函数调用
        if (jQuery.isFunction(processObj['func'])) {
            if (processObj['noSubmitAgain']) {
                if (!processObj['hasSubmit']) {
                    processObj['hasSubmit'] = true;
                    processObj['func'].apply(processObj, processObj['args']);
                }
            }
            else 
                processObj['func'].apply(processObj, processObj['args']);
        }
        delete processObj['elm'];
    };
    SMT.href = function(processObj) {
        //处理之前函数调用，如果返回false将终止
        if (jQuery.isFunction(processObj['callCheck'])) {
            if (!processObj['callCheck']()) 
                return;
        }
        var controller = processObj['c'] ? processObj['c'] : puri;
        var tempUrl = '/' + controller + '.do?xcase=' + processObj['x'];
        if (processObj['argsOrder']) {
            for (var i = 0; i < processObj['argsOrder'].length; i++) {
                if (processObj['args'][i]) {
                    tempUrl += ('&' + processObj['argsOrder'][i] + '=' + processObj['args'][i]);
                }
            }
        }
        if (processObj['needVar']) {
            for (var key in SMT.xconfig.gvar) {
                tempUrl += '&' + key + '=' + SMT.xconfig.gvar[key];
            }
            for (var key in SMT.xconfig.svar) {
                tempUrl += '&' + key + '=' + SMT.xconfig.svar[key];
            }
        }
        var isIframeMode = false;
        if (typeof parent.switchIframeObj != 'undefined') {
            isIframeMode = true;
            parent.switchIframeObj.loadIframe(tempUrl);
        }
        if (!isIframeMode) {
            window.location = tempUrl;
        }
    };
    SMT.waiting = function(display) {
        var waitingObj = parent.$('#waiting');
        if (waitingObj && waitingObj.length == 1) {
            if (display == 'hidden') {
                waitingObj.css('display', 'none');
            }
            else {
                waitingObj.css('top', parent.document.documentElement.scrollTop || (parent.document.body.scrollTop || 0));
                waitingObj.css('display', '');
            }
        }
        else {
            parent.$('body').append('<div id="waiting" style="display:none">正在加载...</div>');
            waitingObj = parent.$('#waiting');
            if (display == 'hidden') {
                waitingObj.css('display', 'none');
            }
            else {
                waitingObj.css('top', SMT.scrollPro().top);
                waitingObj.css('display', '');
            }
        }
    };
    SMT.scrollPro = function(el) {
        var d = el, doc = document;
        if (!d || d == doc || d == doc.body) {
            var l, t;
            if (SMT.browser.msie && SMT.isStrict) {
                l = doc.documentElement.scrollLeft || (doc.body.scrollLeft || 0);
                t = doc.documentElement.scrollTop || (doc.body.scrollTop || 0);
            }
            else {
                l = window.pageXOffset || (doc.body.scrollLeft || 0);
                t = window.pageYOffset || (doc.body.scrollTop || 0);
            }
            return {
                left: l,
                top: t
            };
        }
        else {
            return {
                left: d.scrollLeft,
                top: d.scrollTop
            };
        }
    };
    //取得列表页面所选中的列，返回数组和需要的参数
    SMT.selectData = function() {
        //查找loadTable中的除了全选checkbox以外被选中的checkbox
        var oids = jQuery("input[type=checkbox][id!='allChecked']:enabled:checked", '#content');
        //组装成需要的字符串序列
        var idstr = '';
        for (var i = 0; i < oids.length; i++) {
            idstr += oids[i].value;
            if (i != oids.length - 1) {
                idstr += ',';
            }
        }
        //canRequest表示能否发送请求
        return {
            canRequest: oids.length != 0,
            ids: oids,
            paramValue: idstr
        };
    };
    SMT.analyseUrl = function(url) {
        if (url.indexOf('/') == 0) {
            url = url.substr(1);
        }
        var analyseResult = {};
        analyseResult['c'] = url.substring(0, url.indexOf('.'));
        var params = url.substring(url.indexOf('?') + 1);
        params = params.split('&');
        var pv = null;
        for (var i = 0; i < params.length; i++) {
            pv = params[i].split('=');
            analyseResult[pv[0]] = pv[1];
        }
        return analyseResult;
    };
    SMT.tag_a_click = function() {
        jQuery('body').bind('click', function(e) {
            if (SMT.isNowPop) {
                SMT.isNowPop = false;
            }
            else {
                if (typeof parent.switchObj != 'undefined') {
                    parent.$('.options').css('display', 'none');
                }
                $('.options').css('display', 'none');
            }
            if (document.getElementById('treeMenu')) {
                var treeMenu = document.getElementById('treeMenu').contentWindow;
                if (treeMenu && typeof treeMenu.hasLoad != 'undefined' && treeMenu.hasLoad == true) {
                    if (SMT.browser.msie) 
                        treeMenu.document.body.click();
                    treeMenu.jQuery('.contextMenu').hide();
                }
            }
            element = e.target ? (e.target.nodeType == 3 ? e.target.parentNode : e.target) : e.srcElement;
            var hasChildNode = false;
            if (element.parentNode.tagName.toLowerCase() == 'a') {
                element = element.parentNode;
                hasChildNode = true;
            }
            if (element.tagName.toLowerCase() == 'a') {
                if (typeof calendarGlobal != 'undefined' && calendarGlobal) 
                    calendarGlobal.hide();
                var processObj = null;
                var action = jQuery(element).attr('action');
                //alert(lookup);
                if (SMT.xconfig && (processObj = SMT.xconfig[action])) {
                    processObj['url'] = '/' + action.replace(new RegExp('_', 'gm'), '/');
                    if (processObj['argsOrder']) {
                        processObj['args'] = [];
                        var param = '';
                        for (var i = 0; i < processObj['argsOrder'].length; i++) {
                            param = jQuery(element).attr(processObj['argsOrder'][i].toLowerCase());
                            if (typeof param == 'undefined') {
                                params = '';
                            }
                            processObj['args'].push(param);
                        }
                    }
                    processObj['elm'] = element;
                    //如果a上面有链接则阻止页面的跳转
                    SMT.stopEvent(e);
                    //如果是ajax请求则直接发送
                    if (processObj['func']) {
                        if (!processObj['args']) 
                            processObj['args'] = [];
                        SMT.func(processObj);
                    }
                    else {
                        var field = jQuery(element).attr('f');
                        if (field) {
                            SMT.xconfig.gvar.orderByField = field;
                            SMT.xconfig.gvar.pageNum = '1';
                        }
                        var mode = jQuery(element).attr('m');
                        if (mode) 
                            SMT.xconfig.gvar.orderByMode = mode;
                        processObj['fromClick'] = true;
                        SMT.ajax(processObj);
                    }
                }
            }
        });
    };
    //阻止事件冒泡
    SMT.stopEvent = function(e) {
        if (!e) 
            return;
        if (e.originalEvent) 
            e = e.originalEvent;
        if (e.stopProgation) 
            e.stopProgation();
        else 
            e.cancelBubble = true;
        if (e.preventDefault) 
            e.preventDefault();
        else 
            e.returnValue = false;
    };
    //点击分页跳转列表
    SMT.jumpPage = function(pageNumP, ajaxConfig) {
        SMT.xconfig.gvar.pageNum = pageNumP;
        var pageNums = document.getElementsByName('pageNum');
        if (pageNums) {
            for (var i = 0; i < pageNums.length; i++) {
                pageNums[i].value = pageNumP;
            }
        }
        if (typeof ajaxConfig != 'undefined') {
            if (config[ajaxConfig]['func']) {
                SMT.func(config[ajaxConfig]);
            }
            else {
                SMT.ajax(config[ajaxConfig]);
            }
        }
        else {
            SMT.ajax();
        }
    };
    //改变每页显示数量
    SMT.changePageSize = function(obj, ajaxConfig) {
        SMT.xconfig.gvar.pageNum = '1';
        SMT.xconfig.gvar.pageSize = obj.value;
        if (typeof ajaxConfig != 'undefined') 
            SMT.ajax(config[ajaxConfig]);
        else 
            SMT.ajax();
    };
    //对象属性拷贝
    SMT.copyObj = function(dest, source) {
        for (key in source) {
            dest[key] = source[key];
        }
        return dest;
    };
    //
    var lastCheckBox;
    var checkboxs = [];
    //全选
    SMT.allSelect = function() {
        jQuery('#allChecked').bind('click', function() {
            var checkboxs = jQuery("input[type='checkbox'][name!='productAttributeHot'][name!='productAttributeNew'][name!='productAttributeRec'][id!='allChecked']:enabled");
            for (var i = 0; i < checkboxs.length; i++) {
                if (this.checked) {
                    if (jQuery('#light' + checkboxs[i].value).attr('class').indexOf('light') < 0) {
                        jQuery('#light' + checkboxs[i].value).addClass('light');
                    }
                    if (!jQuery(checkboxs[i]).attr('disbaled')) 
                        jQuery(checkboxs[i]).attr('checked', true);
                }
                else {
                    jQuery('#light' + checkboxs[i].value).removeClass('light');
                    jQuery(checkboxs[i]).attr('checked', false);
                }
            }
        });
    };
    //shift选择
    SMT.shiftSelect = function() {
        checkboxs = [];
        lastCheckBox = null;
        checkboxs = jQuery("input[type='checkbox'][name!='productAttributeHot'][name!='productAttributeNew'][name!='productAttributeRec']");
        for (var i = 0; i < checkboxs.length; i++) {
            if (checkboxs[i].id != 'allChecked') {
                checkboxs[i].onclick = function(e) {
                    e = e || window.event;
                    trObj = this.parentNode.parentNode;
                    trObjClassName = trObj.className;
                    if (this.checked) 
                        trObj.className = trObjClassName.indexOf('light') >= 0 ? trObjClassName : ("light " + trObjClassName);
                    else {
                        trObj.className = trObjClassName.replace('light', '');
                        if (document.getElementById('allChecked')) 
                            document.getElementById('allChecked').checked = false;
                    }
                    if (lastCheckBox && lastCheckBox != this && e.shiftKey) {
                        lastIndex = parseInt(lastCheckBox.getAttribute('index'));
                        nowIndex = parseInt(this.getAttribute('index'));
                        tempIndex = 0;
                        if (lastIndex > nowIndex) {
                            tempIndex = nowIndex;
                            nowIndex = lastIndex;
                            lastIndex = tempIndex;
                        }
                        lastIndex = lastIndex + 1;
                        for (var j = lastIndex; j <= nowIndex; j++) {
                            if (!checkboxs[j] || checkboxs[j].disabled) 
                                continue;
                            if (lastCheckBox.checked) 
                                checkboxs[j].checked = true;
                            else 
                                checkboxs[j].checked = false;
                            if (!checkboxs[j].parentNode) 
                                continue;
                            trObj = checkboxs[j].parentNode.parentNode;
                            trObjClassName = trObj.className;
                            if (checkboxs[j].checked) 
                                trObj.className = trObjClassName.indexOf('light') >= 0 ? trObjClassName : ("light " + trObjClassName);
                            else 
                                trObj.className = trObjClassName.replace('light', '');
                        }
                    }
                    lastCheckBox = this;
                };
            }
        }
    };
    SMT.util.convertHTML2ESC = function(val) {
        val = val.replace(/</gi, '&lt;').replace(/>/gi, '&gt;');
        return val;
    };
    SMT.util.convertESC2HTML = function(val) {
        val = val.replace(/&lt;/gi, '<').replace(/&gt;/gi, '>');
        return val;
    };
    SMT.util.show = function(obj) {
        var objshow = document.getElementById(obj);
        if (!objshow) 
            return;
        var objClass = objshow.className;
        if (objClass.indexOf("collapsed") >= 0) {
            objshow.className = objClass.replace("collapsed", "expanded");
        }
        else {
            if (objClass.indexOf("expanded") < 0) 
                objshow.className = objshow.className + ' expanded';
        }
        if (typeof(Notice) != 'undefined' && Notice) {
            Notice.refresh();
        }
    };
    SMT.util.hide = function(obj) {
        var objhide = document.getElementById(obj);
        if (!objhide) 
            return;
        var objClass = objhide.className;
        if (objClass.indexOf("expanded") >= 0) {
            objhide.className = objClass.replace("expanded", "collapsed");
        }
        else {
            if (objClass.indexOf("collapsed") < 0) 
                objhide.className = objhide.className + ' collapsed';
        }
        if (typeof(Notice) != 'undefined' && Notice) {
            Notice.refresh();
        }
    };
    SMT.util.showNotice = function(noticeId, message) {
        var noticeObj = jQuery('#warNote_' + noticeId);
        if (noticeObj.attr('class') == 'warNote') 
            noticeObj.html('<div>' + message + '</div>');
        else if (noticeObj.attr('class') == 'warNoteInline') 
            noticeObj.html(message);
        else 
            noticeObj.html(message);
        noticeObj.show();
    };
    SMT.util.hideNotice = function() {
        jQuery('.warNote, .warNoteInline').hide();
    };
    SMT.util.showHide = function(obj) {
        var objshow = document.getElementById(obj);
        if (!objshow) 
            return;
        var objClass = objshow.className;
        if (objClass.indexOf("expanded") >= 0) {
            objshow.className = objClass.replace("expanded", "collapsed");
        }
        else {
            objshow.className = objClass.replace("collapsed", "expanded");
        }
    };
    SMT.util.hideShow = function(obj) {
        var objshow = document.getElementById(obj);
        if (!objshow) 
            return;
        var objClass = objshow.className;
        if (objClass.indexOf("expanded") >= 0) {
            objshow.className = objClass.replace("expanded", "collapsed");
        }
        else {
            objshow.className = objClass.replace("collapsed", "expanded");
        }
    };
    //data:text形式数据、name：要插入的节点id、height：高度,可省略、cb:回调，点击树节点的动作、可省略
    SMT.util.onloadTree = function(data, name, height, cb) {
        if (jQuery.isFunction(height)) {
            cb = height;
            height = undefined;
        }
        if (undefined == height) 
            height = "300px";
        var treeObj = document.getElementById("treeboxbox_tree_" + name);
        if (!treeObj) {
            treeObj = parent.document.getElementById("treeboxbox_tree_" + name);
        }
        tree = new dhtmlXTreeObject(treeObj, "100%", height, 0);
        tree.setImagePath("/tree/imgs/");
        tree.setOnClickHandler(function(id, name) {
            if (cb) 
                ~ cb(id, name);
        });
        if (undefined != arguments[3] && 'showCheckbox' == arguments[3]) {
            tree.enableThreeStateCheckboxes(true);
            tree.enableCheckBoxes(true);
        }
        tree.loadXMLString(data);
        return tree;
    };
    // 编辑器相关
    SMT.loadCkeditor = function(id, config) {
        var instance = IEDITOR.instances[id];
        if (instance) {
            IEDITOR.remove(instance);
        }
        if (!!SMT.ckeditor) {
            SMT.ckeditor == null;
        }
        if (typeof config == 'undefined') {
            SMT.ckeditor = IEDITOR.replace(id);
        }
        else {
            SMT.ckeditor = IEDITOR.replace(id, config);
        }
        IEDITOR.on("dialogDefinition", function(ev) {
            var dialogName = ev.data.name;
            var dialogDefinition = ev.data.definition;
            if (dialogName == "image") {
                dialogDefinition.removeContents("advanced");
                dialogDefinition.removeContents("Link");
            }
            else if (dialogName == "link") {
                dialogDefinition.removeContents("advanced");
            }
            else if (dialogName == "flash") {
                dialogDefinition.removeContents("advanced");
            }
        });
        // 注册上传图片回调错误函数
        SMT.ckeditor.on('uploadError', function(e) {
            alert(e.data);
        });
        // 注册上传图片设置alt函数
        SMT.ckeditor.on("uploadSuccess1", function(ev) {
            var altTarget = "info:txtAlt";
            var data = ev.data.customData;
            var dialog = ev.data.dialog;
            var target = altTarget.split(':');
            var element = dialog.getContentElement(target[0], target[1]);
            try {
                var data = (new Function("return " + data))();
                if (element && data) {
                    for (var param in data) {
                        if (param && param.toLowerCase() === 'alt') {
                            element.setValue(data[param]);
                        }
                    }
                }
            } 
            catch (e) {
            }
        });
    }
    SMT.copyEditorHTML = function(isReturn) {
        if (SMT.ckeditor == null) {
            return;
        }
        var editor = SMT.ckeditor;
        var content = editor.getData();
        if (typeof isReturn == 'undefined') {
            // var pattern = new RegExp("<\/?(?!hr|img)[^>]*>|(&nbsp;)", "gim");
            var pattern = new RegExp("&nbsp;", "gim");
            if ($.trim(content.replace(pattern, '')) == '') {
                content = '';
            }
            $('#' + editor.name).val(content);
        }
        return content;
    }
    //
    /*
     SMT.copyEditorHTML = function(isReturn) {
     var content = editor.val();
     // if (SMT.xconfig.gvar.moduleNo != '1') {
     //   var pattern = new RegExp("<(.)+?>|(&nbsp;)", "gim");
     //    if($.trim(content.replace(pattern, ''))==''){
     //      content='';
     //    }
     // }
     var contentVar = new Array();
     var contentDeal = '';
     if (typeof isReturn == 'undefined') {
     var pattern = new RegExp("<\/?(?!hr|img)[^>]*>|(&nbsp;)", "gim");
     if ($.trim(content.replace(pattern, '')) == '') {
     content = '';
     }
     if (navigator.userAgent.toLowerCase().indexOf("msie 8.0") > 0) {
     contentVar = content.split('<A');
     for (var i = 0; i < contentVar.length; i++) {
     if (i + 1 == contentVar.length) {
     contentDeal = contentDeal + contentVar[i];
     }
     else {
     contentDeal = contentDeal + contentVar[i] + '<A target=\"_blank\" ';
     }
     }
     $('#' + editor.textarea_id).val(contentDeal);
     }
     else {
     $('#' + editor.textarea_id).val(content);
     }
     }
     return content;
     };
     */
    //显示本地化信息
    SMT.message = function(code, defaultText) {
        defaultText = typeof(defaultText) == 'undefined' ? '' : defaultText;
        if (typeof(code) == 'undefined' || typeof(messages) == 'undefined') {
            return defaultText;
        }
        var str = messages[config.lans.locale][code];
        return typeof(str) == 'undefined' ? defaultText : str;
    };
    //跳转到首页
    SMT.showIndex = function() {
        if (typeof parent.switchObj != 'undefined') {
            parent.switchObj.showIndex();
        }
        else {
            var url = '/index?locale=' + config.lans.locale + '&lanEdition=' + config.lans.lanEdition;
            window.location = url;
        }
    };
    //防止iframe出现滚动条
    SMT.removeModuleIframeScrollBar = function() {
        if (typeof parent.switchObj == 'undefined') {
            return;
        }
        setInterval(function() {
            //setTimeout(function() {
            if (typeof parent.$ == 'undefined') {
                return;
            }
            if (typeof window.$ == 'undefined') {
                return;
            }
            if (parent.$('#header').length == 0) {
                return;
            }
            var scrollHeight = 0;
            var scrollWidth = 0;
            if (parent.$('#header').css('display') == 'none') {
                scrollHeight = window.innerHeight;
                scrollWidth = window.innerWidth;
            }
            else {
                var contentlength = $('#mainBox').height();
                if (typeof $('#leftBar') != 'undefined' && $('#mainBox').height() < $('#leftBar').height()) {
                    contentlength = $('#leftBar').height();
                }
                scrollHeight = $('#local').height() + contentlength + $('#infoBox').height() + $('#bottom').height() + 50;
                scrollWidth = $(document).width();
            }
            if (typeof scrollHeight == 'undefined') {
                scrollHeight = '966';
            }
            var iframes = parent.document.getElementsByTagName('iframe');
            for (var i = 0; i < iframes.length; i++) {
                if (iframes[i].style.display == '') {
                    if (window['name'] == iframes[i].name) {
                        parent.$('#' + iframes[i].name).attr('height', scrollHeight + 'px');
                        //parent.$('#' + iframes[i].name).attr('width', scrollWidth + 'px');
                    }
                    break;
                }
            }
        }, 1000);
    };
    //将iframe高度进行扩展
    SMT.resizeIframe = function(obj) {
        var Iframe = document.getElementById(obj);
        if (Iframe) {
            if (Iframe.contentDocument) {//ff
                Iframe.style.height = Iframe.contentDocument.documentElement.scrollHeight + 40 + 'px'; //Iframe.contentDocument.body.scrollHeight + 40 +'px';
                //Iframe.scrolling="no";
            }
            else if (Iframe.document && Iframe.document.body.scrollHeight) {//ie
                // 防止msg_body未定义
                if (typeof(msg_body) != 'undefined') {
                    Iframe.style.height = msg_body.document.body.scrollHeight + 40 + 'px';
                    Iframe.scrolling = "no";
                }
            }
            Iframe.removeAttribute('onload');
        }
    };
    // 弹出层遮罩层
    SMT.showScreenLocker = function() {
        if (typeof parent.$ == 'undefined') {
            return;
        }
        if (typeof window.$ == 'undefined') {
            return;
        }
        var html = '<div id="popupLayerScreenLockerSpecial" style="left: 0px; top: 0px; position: absolute; z-index: 1000; zoom: 1; background-image: none; background-attachment: scroll; background-repeat: repeat; background-position-x: 0%; background-position-y: 0%; background-color: rgb(161, 161, 161);">'
        if (parent.$('#popupLayerScreenLockerSpecial').length == 0) {
            parent.$('body').append(html);
        }
        var width = parent.$(document.body).outerWidth(true);
        parent.$('#popupLayerScreenLockerSpecial').width(width + "px");
        parent.$('#popupLayerScreenLockerSpecial').height("107px");
        $.windowResize(function() {
            parent.$('#popupLayerScreenLockerSpecial').width(parent.$(document.body).outerWidth(true) + "px");
        });
        parent.$('#popupLayerScreenLockerSpecial').css({
            opacity: '0.5'
        }).show();
    }
})();
function selectPageSize(obj, ajaxConfig) {
    SMT.changePageSize(obj, ajaxConfig);
}

//由于页头标签封在tag中，目前直接不能用新的js框架，此函数用来进行相关转换
function doEditAction(action) {
    config.saveForm['args'] = [action];
    SMT.func(config.saveForm);
}

function processlimit(error) {
    if (typeof error == 'object' && typeof error['content'] != 'undefined') {
        if ($('#errorMessage').length == 0) {
            $('#content').append('<div class="wr" id="errorMessage" style="-moz-opacity:1;filter:alpha(opacity=100);zoom:1;display: none"></div>');
        }
        $('#errorMessage').html(error['content']).show();
        SMT.waiting('hidden');
    }
}

function checkBoxAllLight(obj1, obj2) {
    var f = document.getElementsByName(obj2);
    var l = f.length;
    var oldClassName = "";
    if (obj1.checked) {
        for (i = 0; i < l; i++) {
            oldClassName = document.getElementById('light' + f[i].value).className;
            if (oldClassName.indexOf('light') < 0) 
                document.getElementById('light' + f[i].value).className = "light " + oldClassName
            if (!f[i].disabled) 
                f[i].checked = true;
        }
    }
    else {
        for (i = 0; i < l; i++) {
            f[i].checked = false;
            var newClassName = document.getElementById('light' + f[i].value).className;
            newClassName = newClassName.substring(6, newClassName.length);
            document.getElementById('light' + f[i].value).className = newClassName;
        }
    }
}

var jtree = new function() {
    this.lastLi = null;
    this.o = function(obj) {
        if (this.lastLi) {
            this.lastLi.removeClass('now');
        }
        var obj$ = $(obj);
        var pLi = obj$.parent('div');
        var ul = pLi.find('div:first');
        if (ul.css('display') == 'none') {
            //height = $(root).height()+obj$.next().height();
            obj$.addClass('col');
            ul.slideDown('slow');
        }
        else {
            obj$.removeClass('col');
            ul.slideUp('slow', function() {
                //height = $(root).height()-obj$.next().height();
            });
        }
    };
    this.s = function(obj) {
        if (this.lastLi) {
            this.lastLi.removeClass('now');
        }
        this.lastLi = $(obj).parent('li').addClass('now');
    };
    this.findRoot = function(obj, level) {
        var root = obj;
        var findNum = level * 2;
        for (var i = 0; i < findNum; i++) {
            root = root.parentNode;
        }
        return root;
    };
}();

function Accordion() {
    this.refreshTree = function() {
        var wrap$ = $('#groupList_content');
        if (wrap$.length == 1) {
            SMT.post('/navigate.do?jspUrl=/ttnProduct/menu&locale=' + config.lans.locale + '&lanEdition=' + config.lans.lanEdition, function(data) {
                wrap$.replaceWith(data);
            });
        }
    };
};

//预览网站
function previewSite(domain) {
    window.open(domain);
}

